<?php

class RequestHandler {
	static function process(){
		while($CurrentRequest = RequestQueue::pull()){
			self::interrupt($CurrentRequest);
		}
	}	
	
	static function interrupt(Request $Request, $return = null){
		$Request->runApplication();
		
		$ResultRegistry = ResultRegistry::getInstance();
		$ResultRegistry->set($Request->getApplicationName(), $Request);
		
		if($return != null){
			return $Request->getResult();
		}
		
		return true;
	}
}

class RequestQueue {
	static private $Queue;
	
	static function push(Request $Request){
		self::$Queue[] = $Request;
		
		return true;
	}
	
	static function pull(){
		$Return = reset(self::$Queue);
		
		$UnsetKey = key(self::$Queue);
		
		unset(self::$Queue[$UnsetKey]);
		
		return $Return;
	}
}

?>